package com.controller;

import com.pojo.Rent;
import com.service.RentService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;

import java.util.List;

@Controller
@RequestMapping(value = "/rent")
public class RentController {

    @Autowired
    private RentService rentService;

    @RequestMapping(value = "/list")
    public String list(Model model){
        List<Rent> list = rentService.list();
        model.addAttribute("list",list);
        return "index";
    }

    @RequestMapping(value = "/toAdd")
    public String toAdd(){
        return "add";
    }

    @RequestMapping(value = "/add")
    public String add(Rent rent){
        int result = rentService.add(rent);
        System.out.println(result);
        return "redirect:/index";
    }

    @RequestMapping(value = "/update")
    public String update(int id,int status){
        if (status == 0){
            int result = rentService.update(id);
            return "redirect:/index";
        }else {
            System.out.println("无法修改");
        }
        return null;
    }

    @RequestMapping(value = "/findList")
    public String findList(Model model,String carNum){
        List<Rent> list = rentService.findlist(carNum);
        model.addAttribute("list",list);
        model.addAttribute("carNum",carNum);
        return "index";
    }
}
